﻿using Microsoft.AspNetCore.Mvc;
using NewLife.Remoting;

namespace newlife.rpc.client.api.Controllers
{
    /// <summary>
    /// 设备服务操作
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeviceServiceController : ControllerBase
    {
        private MyApiClient ApiClient { get; }

        public DeviceServiceController()
        {
            ApiClient = new MyApiClient("tcp://127.0.0.1:8080");
        }

        [HttpGet]
        public async Task<IActionResult> ReportTemperature(float temperature, string deviceId)
        {
            return Ok(await ApiClient.InvokeAsync<bool>
                ("Device/ReportTemperature", new { temperature, deviceId }));
        }

        [HttpGet]
        public async Task<IActionResult> GetSampleRate(string deviceId)
        {
            return Ok(await ApiClient.InvokeAsync<int>("Device/GetSampleRate", new { deviceId }));
        }
    }
}
